import { createRouter, createWebHashHistory, type RouteRecordRaw } from 'vue-router'
import { isMobile } from '@/utils/device'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'Home',
    component: () => import('@/views/workfirst.vue')
  },
  {
    path: '/Todolist',
    name: 'Todolist',
    component: () => import('@/views/TodoList.vue'),
    meta: { forDesktop: true }
  },
  {
    path: '/Todomoble',
    name: 'Todomoble',
    component: () => import('@/views/Todomoble.vue'),
    meta: { forMobile: true }
  },
    {
    path: '/workfirst',
    name: 'workfirst',
    component: () => import('@/views/workfirst.vue'),
  },
    {
    path: '/study',
    name: 'study',
    component: () => import('@/views/study.vue'),
  },
    {
    path: '/person',
    name: 'person',
    component: () => import('@/views/person.vue'),
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

// 导航守卫，防止用户手动访问不匹配的设备路由
router.beforeEach((to, from, next) => {
  if (to.meta.forDesktop && isMobile()) {
    next('/Todomoble')
  } else if (to.meta.forMobile && !isMobile()) {
    next('/Todolist')
  } else {
    next()
  }
})

export default router